#!/bin/sh

# must not fail
set -e 

# debug
#set -x 

echo "Starting $0"


LCSSCRIPTS_DISTNAME=lcs-scripts-1.5.0-beta1.zip
LCSSCRIPTS_DIRNAME=lcs-scripts-1.5.0-beta1
LCSSCRIPTS_SOFTLINK=lcs-scripts
LCSSCRIPTS_UNPACKCMD=unzip


### copy to "install"

if [ ! -f ${DISTFILES_INSTALL}/${LCSSCRIPTS_DISTNAME} ] ; then 	
    echo "copying ${LCSSCRIPTS_DISTNAME} to ${DISTFILES_INSTALL}"
    cp ${LCSSCRIPTS_DISTNAME}     ${DISTFILES_INSTALL}
fi

### unpack if this version dont exist already
if [ -x ${INSTALL_INTO}/${LCSSCRIPTS_DIRNAME} ] ;then
    echo "${LCSSCRIPTS_DIRNAME} exists, skipping"
else

    cd ${INSTALL_INTO}
    ${LCSSCRIPTS_UNPACKCMD} ${DISTFILES_INSTALL}/${LCSSCRIPTS_DISTNAME} 
    cd -
fi


### soft links
rm -f ${LCSSCRIPTS_SOFTLINK}
ln -s ${LCSSCRIPTS_DIRNAME} ${INSTALL_INTO}/${LCSSCRIPTS_SOFTLINK}

### add to environment
echo "export LCSSCRIPTS_HOME=${INSTALL_INTO}/${LCSSCRIPTS_SOFTLINK}" >> ${INSTALL_INTO}/environment


### chmod
chown -R  ${JBOSSUS}.${JBOSSGRP} ${INSTALL_INTO}/${LCSSCRIPTS_DIRNAME}


echo "End of $0"


